package com.dragon.tools.controller;

import com.dragon.tools.pojo.MyRequestBody;
import com.dragon.tools.pojo.MyResponseBody;
import com.dragon.tools.service.impl.GetServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class GetController {

    @Autowired
    GetServiceImpl getService;

    @GetMapping("/generate")
    @ResponseBody
    public MyResponseBody getValue(MyRequestBody requestBody){

        System.out.println("databaseName:"+requestBody.getDatabaseName());
        MyResponseBody body = new MyResponseBody();
        body.setResultCode("200");
        body.setStatus("成功！");
        requestBody.judgeValues(requestBody,body);

        return body;
    }

    @GetMapping("/preview")
    @ResponseBody
    public MyResponseBody previewSql(MyRequestBody request){

        MyResponseBody response = new MyResponseBody();
        response.setResultCode("200");
        response.setStatus("成功！");
        request.judgeValues(request,response);
        MyResponseBody res = getService.previewSql(request, response);
        System.out.println("sql=============\n"+res.getPreviewSql());
        return res;
    }

}
